<template>
  <!-- 登陆：
          1：定义api
          2:导入api
          3:点击确定在表单验证通过后调用api
          4:调用成功
              提示
              存储token
              跳转首页

     not found
       1:路径错误
       2:文件不存在
          a:访问的文件不存在（相当于路径错误）
          b:插件文件不存在  安装插件

  -->
  <div class="login">
    <div class="box">
      <img class="img" src="@/assets/common/login-logo.png" alt="">
      <el-form ref="form" :model="form" :rules="rules">

        <el-form-item prop="mobile">
          <el-input v-model="form.mobile" prefix-icon="el-icon-user-solid" />
        </el-form-item>

        <el-form-item prop="password">
          <!-- 可以让组件支持原生事件  .native:修饰符 -->
          <el-input v-model="form.password" show-password prefix-icon="el-icon-lock" @keyup.enter.native="submit" />
        </el-form-item>
        <el-form-item>
          <!-- 登录 -->
          <el-button class="btn" type="primary" @click="submit">{{ $t('login.login') }}</el-button>
        </el-form-item>
      </el-form>
      <div class="tip">
        帐号:13800000002,密码:123456
      </div>

    </div>

  </div>
</template>
<script>
import { sysLogin } from '@/api/user'
export default {
  data() {
    return {
      test: '',
      form: {
        mobile: '13800000002', //	string	必须		手机号
        password: '123456' //	string	必须		密码
      },
      rules: {
        mobile: [{ required: true, message: '必填', trigger: 'change' }, {
          pattern: /^1[3-9]\d{9}$/, message: '请正确输入手机号', trigger: 'change'
        }], //	string	必须		手机号
        password: [{ required: true, message: '必填', trigger: 'change' },
          { min: 6, max: 12, message: '请输入6-12位密码', trigger: 'change' }
        ]
        //	string	必须		密码
      }
    }
  },
  methods: {
    submit() {
      this.$refs.form.validate(async(result) => {
        if (result) {
          try {
            const res = await sysLogin(this.form)
            console.log('res', res)
            this.$message.success('登录成功')
            this.$store.commit('user/SETTOKEN', res.data)
            this.$router.push('/')
            console.log('登陆成功返回值', res)
          } catch (err) {
            console.log('错误', err)
          }
        }
        console.log(result)
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.login{
  height:100vh;
  background-image: url("~@/assets/common/login.jpg");
  background-repeat: no-repeat;
  background-size: cover;
  display: flex;
  justify-content: center;
  align-items: center;
  .box{
    .img{
      margin-bottom:40px;
    }
    ::v-deep .el-input__inner{
      height:50px;
      background-color: #d4e5ff;
      color:#75b9fe;
    }
    .btn{
      width:100%;
      height:60px;
      color:#fff;
      background-color: #407ffe;
      font-size: 24px;
      font-weight: 500;
    }
    ::v-deep .el-form-item__error{
      color:#fff;
    }
  }
}
</style>
